package com.nowcoder.community.config;

import com.nowcoder.community.controller.interceptor.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private AlphaInterceptor alphaInterceptor;

    @Autowired
    private LoginTicketInterceptor loginTicketInterceptor;

//    废弃之前的拦截检查
//    @Autowired
//    private LoginRequestedInterceptor loginRequestedInterceptor;

    @Autowired
    private MessageInterceptor messageInterceptor;

    @Autowired
    private DataInterceptor dataInterceptor;

    // registry : 注册表
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(alphaInterceptor)
                // "/" 指代 ..../community/ ; **指代css,js目录
                .excludePathPatterns("/**/.css","/**/.js","/**/.png","/**/.jpg","/**/.jpeg")
                // 添加拦截路由
                .addPathPatterns("/login","/register");

        registry.addInterceptor(loginTicketInterceptor)
                .excludePathPatterns("/**/.css","/**/.js","/**/.png","/**/.jpg","/**/.jpeg");

//        registry.addInterceptor(loginRequestedInterceptor)
//                .excludePathPatterns("/**/.css","/**/.js","/**/.png","/**/.jpg","/**/.jpeg");

        registry.addInterceptor(messageInterceptor)
                .excludePathPatterns("/**/.css","/**/.js","/**/.png","/**/.jpg","/**/.jpeg");

        registry.addInterceptor(dataInterceptor)
                .excludePathPatterns("/**/.css","/**/.js","/**/.png","/**/.jpg","/**/.jpeg");

    }
}
